using UnityEngine;

public class FallingObject : MonoBehaviour
{
    public Rigidbody2D rigidbody2D;

    [SerializeField] private float forceAmount;

    private bool isMoving;
    private Vector2 movementDirection;
    private float timeElapsed;

    private void Start()
    {
        rigidbody2D.velocity = Vector3.down * forceAmount;
    }

    private void Update()
    {
        movementDirection = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
        timeElapsed += Time.deltaTime;

        if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.DownArrow) ||
            Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.RightArrow)) isMoving = true;
        if (Input.GetKeyUp(KeyCode.UpArrow) || Input.GetKeyUp(KeyCode.DownArrow) || Input.GetKeyUp(KeyCode.LeftArrow) ||
            Input.GetKeyUp(KeyCode.RightArrow)) isMoving = false;
        if (isMoving) rigidbody2D.velocity = movementDirection * forceAmount;
    }
}